package randRomQuestion;

import java.util.Random;

public class Expression {
	private int max;
	public final static char[] OPER= {'+','-'};
	private Random rand=null;
	
	public Expression(int max) {
		this.max=max;
		rand=new Random();
	}
	
	public String createRandomExpression() {
		int a,b=0,op;
		a=rand.nextInt(max);		
		op=rand.nextInt(this.OPER.length);
		switch(op) {
		case 0:
			b=rand.nextInt(max-a);
			break;
		case 1:
			if(a==0) 
				b=0;
			else 
				b=rand.nextInt(a);	
			break;		
		}
		String exp=String.valueOf(a)+String.valueOf(this.OPER[op])+String.valueOf(b)+"=";
		return exp;
	}	
}
